<template lang="">
    <div>
                 <!-- 表格渲染 -->
    <el-table row-key="id"
    :tree-props="{children: 'children'}"
    default-expand-all
     :data="getMenu" border style="width: 100%">
     <el-table-column prop="id" label="菜单编号" width="180">
     </el-table-column>
     <el-table-column prop="title" label="菜单名称" width="180">
     </el-table-column>
     <el-table-column prop="pid" label="上级菜单"> </el-table-column>
    <el-table-column  label="菜单图标">
        <template slot-scope="item">
          <div>
            <i :class="item.row.icon"></i>
          </div>
        </template>
          </el-table-column>
     <el-table-column prop="url" label="菜单地址"> </el-table-column>
     <el-table-column  label="状态"> 
          <template slot-scope="item">
            <div>
                <el-tag v-if="item.row.status == 1 " type="success">启用</el-tag>
                <el-tag v-else type="danger">禁用</el-tag>
                <!-- {{item.row.status == 1 ? "启用" : "禁用" }} -->
            </div>
          </template>
     </el-table-column>
     <el-table-column  label="操作">
        <template  slot-scope="item">
            <div>
                  <el-button type="primary"  size="mini"   @click="edit(item.row.id)">编辑</el-button>
                  <el-button type="danger" size="mini"  @click="del(item.row.id)">删除</el-button>
            </div>
        </template>
   </el-table-column>
   </el-table>
    </div>
</template>
<script>
import { menuDel } from '../../request/api'
// 辅助性函数
import { mapGetters, mapActions } from 'vuex';
export default {
    computed: {
        ...mapGetters({
            getMenu: 'menu/getMenuList'
        })
    },
    mounted() {
        this.getMenuList()
    },
    methods: {
        ...mapActions({
            getMenuList: 'menu/changeMenuAction'
        }),
        //封装一个编辑事件用来告知父组件打开弹框
        edit(id) {
            this.$emit("edit", id);
        },
        //  封装一个删除事件
        del(id) {
            this.$confirm("你确定要删除这条数据吗", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    // console.log("准备调用删除接口");
                    menuDel({
                        id,
                    }).then((res) => {
                        if (res.code == 200) {
                            this.$message.success(res.msg);
                            //重新触发行动
                            this.getMenuList();
                        } else {
                            this.$message.error(res.msg);
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        }
    }
}
</script>
<style lang="">
    
</style>